package day1;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest {
    public static void main(String[] args) {
        Map<String, String> dict = new HashMap<>();
        //键值对
        //键不重复，不保证顺序
        //put,get,remove
        dict.put("狗", "dog");
        dict.put("猫", "cat");
        dict.put("蛇", "snake");
        dict.put("羊", "sheep");
        dict.put("羊", "goat");
        dict.put("龙", null);
        dict.put(null, "空");

        System.out.println(dict.size());
        System.out.println(dict);
        System.out.println("删除？");
        Scanner in = new Scanner(System.in);
        System.out.println("要删除的键：");
        String key = in.next();
        if (!dict.containsKey(key)) {
            System.out.println("不存在！");
            return;
        }
//        String v2=dict.get(key);
//        if(v2==null){
//            System.out.println("不存在！");
//            return;
//        }
        String value = dict.remove(key);
        System.out.println(key + ":" + value + " 被删除了。。。");
        System.out.println(dict);
    }
}
